package nl.dxn.tunnel.server.http;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.*;

import java.util.List;

public class ResponseDecoder extends HttpObjectDecoder {
    public ResponseDecoder() {
        super(4096, 8192, 8192, true, true, 128, false, true);
    }

    protected HttpMessage createMessage(String[] initialLine) {
        return new DefaultHttpResponse(HttpVersion.valueOf(initialLine[0]), HttpResponseStatus.valueOf(Integer.parseInt(initialLine[1]), initialLine[2]), this.validateHeaders);
    }

    @Override
    public HttpMessage createInvalidMessage() {
        return new DefaultFullHttpResponse(HttpVersion.HTTP_1_0, new HttpResponseStatus(999, "Unknown"), this.validateHeaders);
    }

    @Override
    public void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
        super.decode(ctx, buffer, out);
        super.decodeLast(ctx, buffer, out);
    }

    @Override
    protected boolean isDecodingRequest() {
        return false;
    }
}
